package logic

import (
	"context"
	"month2/C/rpc_C/order"

	"month2/C/api_C/internal/svc"
	"month2/C/api_C/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type EsSearchGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewEsSearchGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EsSearchGoodsLogic {
	return &EsSearchGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *EsSearchGoodsLogic) EsSearchGoods(req *types.EsSearchGoodsRequest) (resp *types.Response, err error) {
	goods, err := l.svcCtx.CRpc.EsSearchGoods(l.ctx, &order.EsSearchGoodsRequest{Keyword: req.Keyword})
	if err != nil {
		return &types.Response{
			Msg:  "es搜索失败",
			Data: nil,
			Code: 500,
		}, nil
	}
	return &types.Response{
		Msg:  "es搜索成功",
		Data: goods,
		Code: 200,
	}, nil
	return
}
